
#include <iostream>
#include <fstream>

using namespace std;

const int LEN = 256;
bool isLetter(int c);
bool isEqualLetter(char c1, char c2);
bool isPalindrome(char * s, int begin, int end);
bool getLongestPalindromeStr(char * s, int length, int * p_begin, int* p_end);
void copy_str(char *s, char *r, int begin, int end);
//bool getLongestPalindromeStr(char * s, int begin, int end, int * pbegin, int * pend);
int main(int argc, char * argv[])
{
    ifstream fin("in.txt", ios_base::in);
    ofstream fout("out.txt", ios_base::out);
    if(!fout)
    {
        cerr<<"failed to open out.txt\n";
        return 1;
    }
    if(!fin)
    {
        cerr<<"failed to open in.txt\n";
        return 1;
    }
    
    char s[LEN];
    char r[LEN];
    fin.getline(s, LEN, '\n');
    int * p_begin = new int(), * p_end = new int();
    *p_begin = -1;
    *p_end = -1;
    int length = (int)strlen(s);
    getLongestPalindromeStr(s, length, p_begin, p_end);
    copy_str(s, r, *p_begin, *p_end);
    fout<<r;
    delete[] p_begin;
    delete[] p_end;
    fin.close();
    fout.close();
    return 0;
}

bool isLetter(int c)
{
    
    if((c>='a'&&c<='z')||(c>='A'&&c<='Z'))
    {
        return true;
    }
    return false;
}

bool isEqualLetter(char c1, char c2)
{
    if(c1 == c2 || c1+'a'-'A'==c2 || c1-'a'+'A' == c2)
    {
        return true;
    }
    return false;
}

bool isPalindrome(char* s, int begin, int end)
{
//    cout<<s[begin]<<" "<<s[end]<<endl;
    if(!isLetter(s[begin])||!isLetter(s[end]))
        return false;
    int i=begin;
    int j=end;
    
    while(i<j)
    {
        while(!isLetter(s[i]))
            i++;
        while(!isLetter(s[j]))
            j--;
        if(isEqualLetter(s[i], s[j]))
        {
            i++;
            j--;
        }
        else
        {
            return false;
        }
    }
    return true;
}

bool getLongestPalindromeStr(char *s, int length, int* p_begin, int * p_end)
{
    //    int p_length = length;
    for(int p_length = length; p_length>0; p_length--)
    {
        for(int i=0; i<=length-p_length; i++)
        {
            if(isPalindrome(s, i,i+p_length-1))
            {
                *p_begin = i;
                *p_end = i+p_length-1;
                return true;
            }
        }
    }
    return false;
}

void copy_str(char *s, char *r, int begin, int end)
{
    int i,j;
    if(begin<0)
        return;
    for(i=begin, j=0; i<=end; i++,j++)
    {
        r[j] = s[i];
    }
    s[j] = '\0';
}









